/**
 * @author none
 *
 */
class TBNNPlayerView extends V.PlayerView
{
    public userInfo: eui.Group;
    public head: eui.Image;
    public headkuang: eui.Image;
    public userInfoBg: eui.Image;
    public nickNameLabel: eui.Label;
    public moneyLabel: eui.Label;
    public bankerIcon: eui.Image;
    public gameEffectPanel: TBNNGameEffectPanel;//特效面板
    public bankerAnimationImg: eui.Image;
    public bankerAnimation: how.Animation;

    // 数据
    public isBanker: boolean = false;
    public lGameScore: number = 0;

    public init():void
    {
        this.start();
    }

    public start(): void 
    {
        this.head.mask = this.headkuang;
        this.bankerAnimation.visible = false;
    }

    public onDestroy(): void 
    {
    }

    public show():boolean
    {
        super.show()
        this.setSitUI(D.App.table.players[this.chairId]);
        return true;
    }

    //设置坐下UI（玩家进入坐下的状态）
    public setSitUI(data: any): void 
    {
        if (data) 
        {
            this.showPlayerInfoPanel();
            this.nickNameLabel.text = this.isMe() ? base.Utils.formatNickName(data.nickName, 10) : data.nickName;
            this.head.source = data.gender == 1 ? "man" + data.faceID + "_png" : "women" + data.faceID + "_png";
            this.getData().gameScore = data.score;
            this.moneyLabel.text = base.Utils.formatCurrency(data.score);
            this.bankerIcon.visible = false;
            this.bankerAnimation.visible = false;
            this.userInfoBg.visible = true;
            this.bankerAnimationImg.visible = false;
            
        }
    }

    //设置离开UI（包括起立、旁观、离开）
    public setLeaveUI(): void 
    {
        this.hidePlayerInfoPanel();
    }

    
    //隐藏用户信息
    public hidePlayerInfoPanel(): void 
    {
        this.userInfo.visible = false;
        this.bankerIcon.visible = false;
        this.userInfoBg.visible = false;
    }

    //显示用户信息
    public showPlayerInfoPanel(): void 
    {
        this.userInfo.visible = true;
        this.bankerIcon.visible = true;
        this.userInfoBg.visible = true;
    }


    //收到游戏开始
    public onGameStart(data: any): void 
    {
        this.isBanker = data.wBankerUser == this.chairId;
        this.lGameScore = 0;
        // this.callUI("showPlayerMoney", this.data.lTakeMoney);
        // this.showPlayerMoney(parseInt(data.lTableUserScore[this.chairId]))
        if(this.isBanker)
        {
            this.playBankerEffect();
        }
    }

        //设置玩家身上的金币数
    public showPlayerMoney(money): void 
    {
        this.moneyLabel.text = base.Utils.formatCurrency(money);
    }

        
    //播放庄家动画
    public playBankerEffect() 
    {
        this.bankerAnimation.visible = true;
        this.bankerAnimation.play();
        this.bankerIcon.visible = false;
    }

    //收到游戏结束
    public onGameEnd(data: any): void 
    {
        this.lGameScore = data.lGameScore[this.chairId];
        if(this.getData())
        {
            this.getData().gameScore += this.lGameScore;
            this.showPlayerMoney(this.getData().gameScore);
        }
    }
}

window["TBNNPlayerView"] || (window["TBNNPlayerView"] = TBNNPlayerView);
